package main

import (
	"fmt"
	"github.com/caddyserver/caddy"
	"github.com/caddyserver/caddy/caddy/caddymain"
	"github.com/caddyserver/caddy/caddyhttp/httpserver"
	"net/http"
)

type AuthRequest struct {
}

func (c AuthRequest) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
	fmt.Println(r.Host)
	return http.StatusOK, nil
}

/*
*
网关，不过用不了
*/
func main() {
	caddy.RegisterPlugin("auth_request", caddy.Plugin{
		ServerType: "http",
		Action:     setup,
	})
	caddymain.Run()
}

func setup(c *caddy.Controller) error {
	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		return &AuthRequest{}
	})

	return nil
}
